#!/usr/bin/python

# pip3 install dnspython
import dns.resolver

ip_list = []

domain = "www.baidu.com"


def get_iplist(domain=""):
    try:
        a_records = dns.resolver.query(domain, 'A')
    except Exception as e:
        print("DNS resolve error: " + e)
        return
    for i in a_records.response.answer:
        for j in i.items:
            if hasattr(j, "address"):
                ip_list.append(j.address)
    return True


if __name__ == '__main__':
    if get_iplist(domain) and len(ip_list) > 0:
        for ip in ip_list:
            print(ip + " = OK")
    else:
        print("dns resolve error!")
